﻿Option Explicit On
Imports System.Net
Imports System.IO
Imports System.Xml
Imports Microsoft.VisualBasic.FileIO
Imports System.Collections.Specialized
Imports System.Text
Imports System.IO.Path
Imports System.Environment
Imports Microsoft.VisualBasic.Devices
Imports System.Management
Imports Microsoft.Win32
Imports System.Net.Sockets

Public Class Form1
    Dim mods As String = Nothing
    Dim directorio As String
    Dim parametros As String
    Dim pantalla As String
    Dim ventana As String
    Dim isChecked As Boolean
    Dim window As String
    Dim splash As String
    Dim world As String
    Dim mundovacio As String
    Dim nopause As String
    Dim solopbo As String
    Dim ningunapausa As String
    Dim mostrarerrores As String
    Dim showscripterror As String
    Dim norpt As String
    Dim nologs As String
    Dim cpus As Integer
    Dim gpu As String
    Dim ram As String
    Dim cpucount As String
    Dim hilosvirtuales As String
    Dim hyperthreading As String
    Dim extrahilos As String
    Dim dias As String
    Dim lunes As String
    Dim martes As String
    Dim miercoles As String
    Dim jueves As String
    Dim viernes As String
    Dim sabado As String
    Dim domingo As String
    Dim seleccion As String
    Dim carpetaa3 As String
    Dim StringCol As New Specialized.StringCollection
    Dim File As File
    Dim pordefecto As String = "Por Defecto.txt"
    Dim pordefectoprioridad As String = "Por Defecto.prioridad.dat"
    Dim perfilesusprioridad As String = "perfilesus(noborrar).prioridad.dat"
    Dim perfilesus As String = "perfilesus(noborrar).dat"
    Dim saltarintro As String
    Dim dx9 As String


    Public Property TextAlign As HorizontalAlignment
    Private programDataFilePath As String = Combine(GetFolderPath(SpecialFolder.ApplicationData), _
                                                My.Application.Info.AssemblyName)
    Private perfilpordefecto As String = Combine(programDataFilePath, pordefecto)
    Private perfilpordefectoprioridad As String = Combine(programDataFilePath, pordefectoprioridad)
    Private perfilesuson As String = Combine(programDataFilePath, perfilesus)
    Private perfilesusprioridadon As String = Combine(programDataFilePath, perfilesusprioridad)
  
    Enum InfoTypes
        OperatingSystemName
        ProcessorName
        AmountOfMemory
        VideocardName
        VideocardMem
    End Enum

    Public Function GetInfo(ByVal InfoType As InfoTypes) As String
        Dim Info As New ComputerInfo : Dim Value, vganame, vgamem, proc As String
        Dim searcher As New Management.ManagementObjectSearcher( _
            "root\CIMV2", "SELECT * FROM Win32_VideoController")
        Dim searcher1 As New Management.ManagementObjectSearcher( _
            "SELECT * FROM Win32_Processor")
        If InfoType = InfoTypes.OperatingSystemName Then
            Value = Info.OSFullName
        ElseIf InfoType = InfoTypes.ProcessorName Then
            For Each queryObject As ManagementObject In searcher1.Get
                proc = queryObject.GetPropertyValue("Name").ToString
            Next
            Value = proc
        ElseIf InfoType = InfoTypes.AmountOfMemory Then
            Value = Math.Round((((CDbl(Convert.ToDouble(Val(Info.TotalPhysicalMemory))) / 1024)) / 1024), 2)
        ElseIf InfoType = InfoTypes.VideocardName Then
            For Each queryObject As ManagementObject In searcher.Get
                vganame = queryObject.GetPropertyValue("Name").ToString
            Next
            Value = vganame
        ElseIf InfoType = InfoTypes.VideocardMem Then
            For Each queryObject As ManagementObject In searcher.Get
                vgamem = queryObject.GetPropertyValue("AdapterRAM").ToString
            Next
            Value = Math.Round((((CDbl(Convert.ToDouble(Val(vgamem))) / 1024)) / 1024), 2)
        End If
        Return Value
    End Function


    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    End Sub


    Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TabControl1.SelectedIndex = 1
        cpus = TrackBar1.Value.ToString
        ram = TrackBar2.Value.ToString
        gpu = TrackBar3.Value.ToString
        extrahilos = TrackBar4.Value.ToString
        Dim builder As New StringBuilder()
        For Each i As Object In ListBox2.Items
            i = i + ";"
            builder.Append(i.ToString())
        Next
        TextBox6.Text = builder.ToString()
        parametros = window & " " & splash & " " & world & " " & nopause & " " & showscripterror & " " & "-mod=" & TextBox6.Text & " " & nologs & " " & solopbo & " " & dx9 & " " & saltarintro & " " & "-cpuCount=" & cpus & " " & "-high" & "" & "-maxMem=" & ram & " " & "-maxvram=" & gpu & " " & hyperthreading & " " & "-exthreads=" & extrahilos
        TextBox1.Text = parametros
        TabControl1.SelectedIndex = 0
        If CheckBox14.CheckState = CheckState.Checked Then
            Process.Start("C:\Fraps\fraps.exe")
        Else

        End If
        If CheckBox16.CheckState = CheckState.Checked Then
            Dim procStartInfo As New ProcessStartInfo
            Dim procExecuting As New Process

            With procStartInfo
                .UseShellExecute = True
                .FileName = directorio
                .WindowStyle = ProcessWindowStyle.Normal
                .Arguments = parametros
                .Verb = "runas" 'add this to prompt for elevation
            End With

            procExecuting = Process.Start(procStartInfo)

        Else
            Process.Start(directorio, parametros)

        End If
        If ComboBox3.SelectedIndex = 0 Then

        End If
        If ComboBox3.SelectedIndex = 1 Then
            Me.WindowState = FormWindowState.Minimized

        End If
        If ComboBox3.SelectedIndex = 2 Then
            Me.Close()

        End If
    End Sub

    Private Sub CheckBox1_CheckStateChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckStateChanged
        If CheckBox1.Checked = True Then
            ventana = "-window"
        Else
            ventana = Nothing
        End If
        window = ventana

    End Sub



    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
        If CheckBox2.Checked = True Then
            pantalla = "-nosplash"
        Else
            pantalla = Nothing
        End If
        splash = pantalla

    End Sub
    Private Sub CheckBox3_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox3.CheckedChanged
        If CheckBox3.Checked = True Then
            mundovacio = "-world=empty"
        Else
            mundovacio = Nothing
        End If
        world = mundovacio
    End Sub


    Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox4.CheckedChanged
        If CheckBox4.Checked = True Then
            ningunapausa = "-noPause"
        Else
            ningunapausa = Nothing
        End If
        nopause = ningunapausa
    End Sub
    Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.CheckedChanged
        If CheckBox8.Checked = True Then
            mostrarerrores = "-showScriptErrors"
        Else
            mostrarerrores = Nothing
        End If
        showscripterror = mostrarerrores
    End Sub
    Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox9.CheckedChanged
        If CheckBox9.Checked = True Then
            norpt = "-noLogs"
        Else
            norpt = Nothing
        End If
        nologs = norpt
    End Sub
    Private Sub CheckBox10_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox10.CheckedChanged
        If CheckBox10.Checked = True Then
            hilosvirtuales = "-enableHT"
        Else
            hilosvirtuales = Nothing
        End If
        hyperthreading = hilosvirtuales
    End Sub
    Private Sub CheckBox11_CheckedChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged

    End Sub



    Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged

    End Sub

    Private Sub HScrollBar3_Scroll(sender As Object, e As ScrollEventArgs)

    End Sub
    Private Sub HScrollBar3_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    End Sub

    Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
    End Sub

    Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox5.CheckedChanged
        If CheckBox5.Checked = True Then
            TextBox2.Visible = True
            TrackBar1.Visible = True
        Else

            TextBox2.Visible = False
            TrackBar1.Visible = False
        End If
    End Sub

    Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox6.CheckedChanged
        If CheckBox6.Checked = True Then
            TextBox4.Visible = True
            TrackBar2.Visible = True
        Else
            TextBox4.Visible = False
            TrackBar2.Visible = False

        End If
    End Sub

    Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.CheckedChanged
        If CheckBox7.Checked = True Then
            TextBox3.Visible = True
            TrackBar3.Visible = True
        Else
            TextBox3.Visible = False
            TrackBar3.Visible = False

        End If
    End Sub




    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

    End Sub


    Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged

        If My.Computer.FileSystem.FileExists(perfilesuson) Then
            Try
                Using rdr As New System.IO.StreamReader(perfilesuson)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox2.Items.Count - 1
                                If CheckedListBox2.Items(i).ToString = itm Then
                                    CheckedListBox2.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If

        If IO.File.Exists(perfilesusprioridadon) Then
            Try
                Dim r As New IO.StreamReader(perfilesusprioridadon)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox3.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox3.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try
        End If

    End Sub



    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            dias = ComboBox2.SelectedItem.ToString()
        Catch ex As Exception

        End Try
        Dim lunes As New WebClient
        Dim martes As New WebClient
        Dim miercoles As New WebClient
        Dim jueves As New WebClient
        Dim viernes As New WebClient
        Dim sabado As New WebClient
        Dim domingo As New WebClient
        Dim predefinido As String
        If dias = "LUNES" Then
            Try
                predefinido = lunes.DownloadString("https://dl.dropboxusercontent.com/u/228510208/lunes/prueba.txt")

            Catch ex As WebException
                MessageBox.Show(ex.ToString)
            End Try
        End If
        If dias = "MARTES" Then
            Try
                predefinido = martes.DownloadString("https://dl.dropboxusercontent.com/u/228510208/martes/prueba.txt")


            Catch ex As WebException
                MessageBox.Show(ex.ToString)
            End Try
        End If
        If dias = "MIÉRCOLES" Then
            Try
                predefinido = miercoles.DownloadString("https://dl.dropboxusercontent.com/u/228510208/miercoles/prueba.txt")

            Catch ex As WebException
                MessageBox.Show(ex.ToString)
            End Try
        End If

        TabControl1.SelectedIndex = 1
        cpus = TrackBar1.Value.ToString
        ram = TrackBar2.Value.ToString
        gpu = TrackBar3.Value.ToString
        Dim builder As New StringBuilder()
        For Each i As Object In ListBox3.Items
            i = i + ";"
            builder.Append(i.ToString())
        Next
        TextBox10.Text = builder.ToString()
        extrahilos = TrackBar4.Value.ToString
        parametros = window & " " & splash & " " & world & " " & nopause & " " & showscripterror & " " & "-mod=" & predefinido & TextBox10.Text & " " & nologs & " " & saltarintro & " " & solopbo & " " & dx9 & " " & "-cpuCount=" & cpus & " " & "-high" & "" & "-maxMem=" & ram & " " & "-maxvram=" & gpu & " " & hyperthreading & " " & "-exthreads=" & extrahilos
        TextBox10.Text = parametros
        TabControl1.SelectedIndex = 0

        If CheckBox14.CheckState = CheckState.Checked Then
            Process.Start("C:\Fraps\fraps.exe")
        Else

        End If

        If CheckBox16.CheckState = CheckState.Checked Then
            Dim procStartInfo As New ProcessStartInfo
            Dim procExecuting As New Process

            With procStartInfo
                .UseShellExecute = True
                .FileName = directorio
                .WindowStyle = ProcessWindowStyle.Normal
                .Arguments = parametros
                .Verb = "runas" 'add this to prompt for elevation
            End With

            procExecuting = Process.Start(procStartInfo)

        Else
            Process.Start(directorio, parametros)

        End If
        If ComboBox3.SelectedIndex = 0 Then
        End If
        If ComboBox3.SelectedIndex = 1 Then
            Me.WindowState = FormWindowState.Minimized
        End If
        If ComboBox3.SelectedIndex = 2 Then
            Me.Close()

        End If
    End Sub



    Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs)

    End Sub



    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs)

    End Sub




    Private Sub TabPage1_Click(sender As Object, e As EventArgs) Handles TabPage1.Click

    End Sub

    Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs)

    End Sub




    Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
        Label1.Visible = True

        Label1.Text = "¡Datos Guardados!"
        Label1.Refresh()
        System.Threading.Thread.Sleep(500)
        Label1.Visible = False
        My.Settings.saltarpantalla = CheckBox2.CheckState
        My.Settings.modoventana = CheckBox1.CheckState
        My.Settings.mundovacio = CheckBox3.CheckState
        My.Settings.ningunapausa = CheckBox4.CheckState
        My.Settings.mostrarerrores = CheckBox8.CheckState
        My.Settings.trackir = CheckBox13.CheckState
        My.Settings.freetrack = CheckBox15.CheckState
        My.Settings.nologs = CheckBox9.CheckState
        My.Settings.fraps = CheckBox14.CheckState
        My.Settings.memoriaram = CheckBox6.CheckState
        My.Settings.memoriavideo = CheckBox7.CheckState
        My.Settings.numerodecpu = CheckBox5.CheckState
        My.Settings.activarhyper = CheckBox10.CheckState
        My.Settings.logindesarrollo = Label9.Text
        My.Settings.extrahiloscheck = CheckBox11.CheckState
        My.Settings.rutacarpetaa3 = TextBox9.Text
        My.Settings.rutacambiada = TextBox8.Text
        My.Settings.rutaarmacheck = CheckBox12.CheckState
        My.Settings.despuesdelanzar = Me.ComboBox3.SelectedItem
        My.Settings.modoadministrador = CheckBox16.CheckState
        My.Settings.solopbo = CheckBox17.CheckState
        My.Settings.saltarintro = CheckBox18.CheckState
        My.Settings.dx9 = CheckBox19.CheckState
        My.Settings.Save()
        Dim seleccion As String
        Try
            seleccion = ComboBox1.SelectedItem.ToString()
        Catch ex As Exception
        End Try
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        Dim sb As New System.Text.StringBuilder
        For Each itm As String In CheckedListBox1.CheckedItems
            sb.AppendLine(itm)
        Next
        If sb.ToString.Length >= 0 Then
            My.Computer.FileSystem.WriteAllText(rutaguardado, sb.ToString, False)
        End If

        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        Dim s As New IO.StreamWriter(rutaguardadolista)
        For i As Integer = 0 To ListBox2.Items.Count - 1
            s.Write(ListBox2.Items(i) & vbNewLine)
        Next
        s.Close()
    End Sub
    Sub numerodecpu()
        If CheckBox5.CheckState = CheckState.Checked Then
            TextBox2.Visible = True
            TextBox2.Enabled = False

            TrackBar1.Visible = True
        Else
            TextBox2.Visible = False
            TextBox2.Enabled = False

            TrackBar1.Visible = False
        End If
    End Sub


    Sub extrahiloscheck()
        If CheckBox11.CheckState = CheckState.Checked Then
            TrackBar4.Visible = True
            TextBox5.Visible = True
        Else
            TrackBar4.Visible = False
            TextBox5.Visible = False
        End If
    End Sub
    Sub rutas()
        Dim steampath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
        Label2.Text = steampath & "\SteamApps\common\Arma 3\arma3.exe"
        Label10.Text = steampath & "\SteamApps\common\Arma 3"
        If CheckBox12.CheckState = CheckState.Checked Then
            Label2.Visible = False
            Label10.Visible = False
            TextBox8.Visible = True
            TextBox9.Visible = True
            Button21.Visible = True
            Button22.Visible = True
        Else
            Label2.Visible = True
            Label10.Visible = True
            TextBox8.Visible = False
            TextBox9.Visible = False
            Button21.Visible = False
            Button22.Visible = False
            TextBox8.Text = ""
            TextBox9.Text = ""
        End If
    End Sub
    Sub memoriaram()
        If CheckBox6.CheckState = CheckState.Checked Then

            TextBox4.Visible = True
            TextBox4.Enabled = False

            TrackBar2.Visible = True
        Else
            TextBox4.Visible = False
            TextBox4.Enabled = False

            TrackBar2.Visible = False

        End If
    End Sub
    Sub memoriavideo()
        If CheckBox7.CheckState = CheckState.Checked Then

            TextBox3.Visible = True
            TrackBar3.Visible = True
        Else
            TrackBar3.Visible = False
            TextBox3.Visible = False
        End If
    End Sub

    Sub logindesarrollador()
        If Label9.Text = "Estas logueado como desarrollador" Then
            Label9.Visible = True
            Button14.Visible = False
            Button8.Visible = True
            Button15.Visible = True
            Button18.Visible = True
        Else
            Label9.Visible = False
            Button14.Visible = True
            Button8.Visible = False
            Button15.Visible = False
            Button18.Visible = False

        End If
    End Sub

   
    Sub activarhyper()
        If CheckBox10.CheckState = CheckState.Checked Then

            hilosvirtuales = "-enableHT"
            TrackBar4.Visible = True
            TextBox5.Enabled = False

            TextBox5.Visible = True

        Else
            hilosvirtuales = Nothing
            TrackBar4.Visible = False
            TextBox5.Visible = False
            TextBox5.Enabled = False


        End If
        hyperthreading = hilosvirtuales
    End Sub


    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

    End Sub

    Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles TabPage2.Click

    End Sub


    Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
        TextBox2.Enabled = False
        TextBox2.Text = TrackBar1.Value
        My.Settings.valuecpu = TrackBar1.Value
        My.Settings.Save()
    End Sub

    Private Sub TrackBar2_Scroll(sender As Object, e As EventArgs) Handles TrackBar2.Scroll
        TextBox4.Enabled = False
        TextBox4.Text = TrackBar2.Value
        My.Settings.valueram = TrackBar2.Value
        My.Settings.Save()
    End Sub

    Private Sub TrackBar3_Scroll(sender As Object, e As EventArgs) Handles TrackBar3.Scroll
        TextBox3.Enabled = False
        TextBox3.Text = TrackBar3.Value
        My.Settings.valuevideo = TrackBar3.Value
        My.Settings.Save()
    End Sub

    Private Sub Button4_Click_1(sender As Object, e As EventArgs) Handles Button4.Click
        Dim checked As Boolean = False
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemChecked(i, checked)
        Next
        ListBox2.Items.Clear()
        For Each item In CheckedListBox1.CheckedItems
            ListBox2.Items.Add(item.ToString)
        Next
    End Sub

    Private Sub TrackBar4_Scroll(sender As Object, e As EventArgs) Handles TrackBar4.Scroll
        extrahilos = TrackBar4.Value
        TextBox5.Enabled = False
        TextBox5.Text = TrackBar4.Value
        My.Settings.valuehilos = TrackBar4.Value
        My.Settings.Save()
    End Sub

    Private Sub TextBox5_TextChanged_1(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
    End Sub


   
    Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged

    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        Dim texto As String = TextBox7.Text
        Dim extension As String = ".txt"

        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = texto & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)

        Dim outpout As String

        outpout = texto & extension
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)

        TextBox7.Text = ""
        Dim sb As New System.Text.StringBuilder
        Dim checked As Boolean = False
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemChecked(i, checked)
        Next

        For Each itm As String In CheckedListBox1.CheckedItems
            sb.AppendLine(itm)
        Next

        If sb.ToString.Length >= 0 Then
            My.Computer.FileSystem.WriteAllText(rutaguardado, sb.ToString, False)
        End If
        ListBox1.Items.Clear()
        ComboBox1.Items.Clear()

        For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
    (programDataFilePath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
            ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))
            ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))

        Next
        Dim itemlistbox As String
        ListBox1.SelectedItem = "Por Defecto"
        itemlistbox = ListBox1.SelectedItem
        ListBox1.Items.Remove(itemlistbox)
        ListBox1.Items.Insert(0, itemlistbox)
        ListBox1.SelectedIndex = 0
        Dim comboboxitem As String
        ComboBox1.SelectedItem = "Por Defecto"
        comboboxitem = ComboBox1.SelectedItem
        ComboBox1.Items.Remove(comboboxitem)
        ComboBox1.Items.Insert(0, comboboxitem)
        ComboBox1.SelectedIndex = 0
        Dim s As New IO.StreamWriter(rutaguardadolista)
        For i As Integer = 0 To ListBox2.Items.Count - 1
            s.Write(ListBox2.Items(i) & vbNewLine)
        Next
        s.Close()
        ListBox1.SelectedItem = Nothing
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim seleccion As String = ComboBox1.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Try
                Using rdr As New System.IO.StreamReader(rutaguardado)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                                If CheckedListBox1.Items(i).ToString = itm Then
                                    CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Try
                Dim r As New IO.StreamReader(rutaguardadolista)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox2.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox2.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try
        End If

    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click

        Dim checked As Boolean = True
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemChecked(i, checked)
        Next
        ListBox2.Items.Clear()
        For Each item In CheckedListBox1.CheckedItems
            ListBox2.Items.Add(item.ToString)
        Next
    End Sub



    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        Ping.Show()
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If ListBox2.SelectedIndex > 0 Then
            Dim I = ListBox2.SelectedIndex - 1
            ListBox2.Items.Insert(I, ListBox2.SelectedItem)
            ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
            ListBox2.SelectedIndex = I
        End If
    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        If ListBox2.SelectedIndex < ListBox2.Items.Count - 1 Then
            Dim I = ListBox2.SelectedIndex + 2
            ListBox2.Items.Insert(I, ListBox2.SelectedItem)
            ListBox2.Items.RemoveAt(ListBox2.SelectedIndex)
            ListBox2.SelectedIndex = I - 1
        End If
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        Dim item As String
        item = ListBox2.SelectedItem
        ListBox2.Items.Remove(item)
        ListBox2.Items.Insert(0, item)
        ListBox2.SelectedIndex = 0
    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        Dim limite As Integer = (ListBox2.Items.Count - 1)
        Dim item As String
        item = ListBox2.SelectedItem
        ListBox2.Items.Remove(item)
        ListBox2.Items.Insert(limite, item)
        ListBox2.SelectedIndex = limite
    End Sub

    Private Sub ListBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox2.SelectedIndexChanged

    End Sub

    Private Sub TabPage5_Click(sender As Object, e As EventArgs) Handles TabPage5.Click

    End Sub

    Private Sub CheckedListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox1.SelectedIndexChanged
        Button7.Enabled = True
        Button4.Enabled = True
        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Dim r As New IO.StreamReader(rutaguardadolista)
            Dim txt As New TextBox
            txt.Text = r.ReadToEnd
            ListBox2.Items.Clear()
            For i As Integer = 0 To txt.Lines.Count - 2
                ListBox2.Items.Add(txt.Lines(i))
            Next
            r.Close()
        Else
            ListBox2.Items.Clear()
            If CheckedListBox1.CheckedItems.Count > 0 Then
                For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
                    ListBox2.Items.Add(CheckedListBox1.CheckedItems(i))
                Next
            End If

        End If
    End Sub


    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        CheckedListBox1.Items.Clear()
        CheckedListBox1.Refresh()
        ListBox2.Items.Clear()
        Try
            For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@*")
                CheckedListBox1.Items.Add(Path.GetFileName(folder))
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        Dim seleccion As String = ComboBox1.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Using rdr As New System.IO.StreamReader(rutaguardado)
                Do While rdr.Peek() >= 0
                    Dim itm As String = rdr.ReadLine
                    itm = itm.Trim

                    If itm <> "" Then
                        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                            If CheckedListBox1.Items(i).ToString = itm Then
                                CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
                                Exit For
                            End If
                        Next
                    End If
                Loop
            End Using
        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Dim r As New IO.StreamReader(rutaguardadolista)
            Dim txt As New TextBox
            txt.Text = r.ReadToEnd
            ListBox2.Items.Clear()
            For i As Integer = 0 To txt.Lines.Count - 2
                ListBox2.Items.Add(txt.Lines(i))
            Next
            r.Close()
        End If
    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click

    End Sub

    Private Sub TextBox8_TextChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub TextBox9_TextChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button16_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub TextBox12_TextChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub TextBox10_TextChanged(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Button17.Click
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            If CheckedListBox1.GetItemChecked(i) = True Then
                CheckedListBox1.SetItemChecked(i, False)
            ElseIf CheckedListBox1.GetItemChecked(i) = False Then
                CheckedListBox1.SetItemChecked(i, True)
            End If
        Next
    End Sub

    Private Sub CheckedListBox2_SelectedIndexChanged(sender As Object, e As EventArgs)

    End Sub



    Private Sub LoadCLB_Items(ByVal textFileName As String)

        If My.Computer.FileSystem.FileExists(textFileName) Then
            CheckedListBox1.BeginUpdate()

            Using rdr As New System.IO.StreamReader(textFileName)
                Do While rdr.Peek() >= 0
                    Dim itm As String = rdr.ReadLine
                    itm = itm.Trim

                    If itm <> "" Then
                        CheckedListBox1.Items.Add(itm, False)
                    End If
                Loop
            End Using

            CheckedListBox1.EndUpdate()
        End If

    End Sub

    Private Sub Button14_Click(sender As Object, e As EventArgs)

    End Sub
    Dim storedx As Integer
    Dim storedy As Integer
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        storedx = e.X
        storedy = e.Y
    End Sub
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.Left = e.X - storedx + Me.Left
            Me.Top = e.Y - storedy + Me.Top
        End If
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
       Handles MyBase.Load
        Me.BackColor = Color.FromArgb(255, 162, 0)
        If Not My.Computer.FileSystem.DirectoryExists(programDataFilePath) Then
            My.Computer.FileSystem.CreateDirectory(programDataFilePath)

        End If
        TextBox10.Visible = False
        Label2.Visible = False
        ComboBox2.Visible = False
        Label10.Visible = False
        Button24.Visible = False
        TabPage3.Enabled = True
        Button29.Visible = False
        Button30.Visible = False
        Button31.Visible = False
        Button32.Visible = False

        ListBox5.Visible = False
        CheckedListBox3.Visible = False
        ListBox4.Visible = False
        ListBox3.Visible = False
        Button4.Visible = True
        Button7.Visible = True
        Button17.Visible = True
        Button13.Visible = True
        Button25.Visible = False
        Button26.Visible = False
        Button27.Visible = False
        Button28.Visible = False

        Dim fs As FileStream = Nothing
        If (Not File.Exists(perfilpordefecto)) Then
            fs = File.Create(perfilpordefecto)
            fs = File.Create(perfilpordefectoprioridad)
            fs = File.Create(perfilesuson)
            fs = File.Create(perfilesusprioridadon)
            Using fs
            End Using
        End If
        With CheckedListBox1
            .CheckOnClick = True
            .Sorted = True
        End With
        Dim uniqueNamesPath As String = _
        Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "archivoskrach.txt")
        LoadCLB_Items(uniqueNamesPath)
        TextBox1.Visible = False
        TextBox8.Visible = False
        TextBox9.Visible = False
        TextBox6.Visible = False
        Button21.Visible = False
        Button22.Visible = False
        Button2.Visible = False
        CheckedListBox2.Visible = False
        ProgressBar1.Visible = False
        TextBox2.Text = TrackBar1.Value
        TextBox4.Text = TrackBar2.Value
        TextBox3.Text = TrackBar3.Value
        TextBox5.Text = TrackBar4.Value
        Timer1.Enabled = False
        Label12.Visible = False
        Timer1.Interval = 10
        ProgressBar1.Value = 0
        ProgressBar1.Maximum = 100
        ProgressBar1.Step = 20
        Dim version As String
        Dim versión As New WebClient
        Label1.Visible = False
        If Not My.Settings.valuecpu = vbNullString Then
            TrackBar1.Value = My.Settings.valuecpu
        End If

        If Not My.Settings.valueram = vbNullString Then
            TrackBar2.Value = My.Settings.valueram
        End If
        If Not My.Settings.valuevideo = vbNullString Then
            TrackBar2.Value = My.Settings.valuevideo
        End If
        If Not My.Settings.valuehilos = vbNullString Then
            TrackBar4.Value = My.Settings.valuehilos
        End If

        Try
            If My.Computer.FileSystem.FileExists("C:\Program Files (x86)\Steam\SteamApps\common\Arma 3") Then
                directorio = "C:\Program Files (x86)\Steam\SteamApps\common\Arma 3\arma3.exe"
                carpetaa3 = "C:\Program Files (x86)\Steam\SteamApps\common\Arma 3"
            Else
                If My.Computer.FileSystem.FileExists("D:\Program Files (x86)\Steam\SteamApps\common\Arma 3") Then
                    directorio = "D:\Program Files (x86)\Steam\SteamApps\common\Arma 3\arma3.exe"
                    carpetaa3 = "D:\Program Files (x86)\Steam\SteamApps\common\Arma 3"
                Else
                    If My.Computer.FileSystem.FileExists("E:\Program Files (x86)\Steam\SteamApps\common\Arma 3") Then
                        directorio = "E:\Program Files (x86)\Steam\SteamApps\common\Arma 3\arma3.exe"
                        carpetaa3 = "E:\Program Files (x86)\Steam\SteamApps\common\Arma 3"
                    Else
                        If My.Computer.FileSystem.FileExists("F:\Program Files (x86)\Steam\SteamApps\common\Arma 3") Then
                            directorio = "F:\Program Files (x86)\Steam\SteamApps\common\Arma 3\arma3.exe"
                            carpetaa3 = "F:\Program Files (x86)\Steam\SteamApps\common\Arma 3"
                        Else
                            Dim steampath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
                            If TextBox8.Text = "" Then
                                directorio = steampath & "\SteamApps\common\Arma 3\arma3.exe"
                                carpetaa3 = steampath & "\SteamApps\common\Arma 3"
                            Else
                                directorio = TextBox8.Text
                                carpetaa3 = TextBox9.Text
                            End If
                        End If
                    End If
                End If
            End If
        Catch
            MessageBox.Show("No se ha podido encontrar la ruta de Arma 3 desde el registro,eligela manualmente")
        End Try



        Try
            version = versión.DownloadString("https://dl.dropboxusercontent.com/u/228510208/version/versi%C3%B3n.txt")
            Label5.Text = version

        Catch ex As WebException
            MessageBox.Show(ex.ToString)
            Label5.Text = "versión no disponible"
        End Try

        TextBox3.Enabled = False
        Call numerodecpu()
        Call memoriaram()
        Call memoriavideo()
        Call activarhyper()
        Call logindesarrollador()
        Call extrahiloscheck()
        Call rutas()
        Try
            ComboBox3.SelectedItem = My.Settings.despuesdelanzar

        Catch ex As Exception

        End Try
        ComboBox1.Items.Clear()
        For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
        (programDataFilePath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
            ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))
            ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))

        Next


        If Not My.Computer.FileSystem.DirectoryExists(programDataFilePath) Then
            My.Computer.FileSystem.CreateDirectory(programDataFilePath)
        End If

        With CheckedListBox1
            .CheckOnClick = True
            .Sorted = True
        End With
        Dim itemlistbox As String
        ListBox1.SelectedItem = "Por Defecto"
        itemlistbox = ListBox1.SelectedItem
        ListBox1.Items.Remove(itemlistbox)
        ListBox1.Items.Insert(0, itemlistbox)
        ListBox1.SelectedIndex = 0
        Dim comboboxitem As String
        ComboBox1.SelectedItem = "Por Defecto"
        comboboxitem = ComboBox1.SelectedItem
        ComboBox1.Items.Remove(comboboxitem)
        ComboBox1.Items.Insert(0, comboboxitem)
        ComboBox1.SelectedIndex = 0
        Dim folder As String
        CheckedListBox1.Items.Clear()
        Try
            For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@*")
                CheckedListBox1.Items.Add(Path.GetFileName(folder))
            Next
        Catch ex As Exception

        End Try
        Dim seleccion As String = ComboBox1.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Try
                Using rdr As New System.IO.StreamReader(rutaguardado)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                                If CheckedListBox1.Items(i).ToString = itm Then
                                    CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception
                MessageBox.Show("No se ha podido encontrar la ruta de Arma 3 desde el registro,eligela manualmente")
            End Try

        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Try
                Dim r As New IO.StreamReader(rutaguardadolista)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox2.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox2.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try

        End If
        ListBox1.SelectedItem = Nothing
    End Sub



    Private Sub ListBox1_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub

    Private Sub TabPage3_Click(sender As Object, e As EventArgs) Handles TabPage3.Click

    End Sub

    Private Sub TextBox10_TextChanged_1(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button14_Click_1(sender As Object, e As EventArgs) Handles Button14.Click
        Desarrollador.Show()

    End Sub

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        TabControl1.SelectedIndex = 1
        TextBox6.Visible = True
        Button16.Visible = True
        cpus = TrackBar1.Value.ToString
        ram = TrackBar2.Value.ToString
        gpu = TrackBar3.Value.ToString
        extrahilos = TrackBar4.Value.ToString
        Dim builder As New StringBuilder()
        For Each i As Object In ListBox2.Items
            i = i + ";"
            builder.Append(i.ToString())
        Next
        TextBox6.Text = builder.ToString()
        TabControl1.SelectedIndex = 2

    End Sub

    Private Sub Button16_Click_1(sender As Object, e As EventArgs) Handles Button16.Click
        Try
            Clipboard.SetText(TextBox6.Text)
        Catch ex As Exception
            MessageBox.Show("No se ha podido copiar nada, debes seleccionar primero los addons")
        End Try
    End Sub

    Private Sub Button18_Click(sender As Object, e As EventArgs) Handles Button18.Click
        Label9.Text = ""
        Label9.Visible = False
        Button14.Visible = True
        Button8.Visible = False
        Button15.Visible = False
        Button16.Visible = False
        Button18.Visible = False
        TextBox6.Visible = False
        Button23.Visible = True
    End Sub

    Private Sub Button19_Click(sender As Object, e As EventArgs) Handles Button19.Click
        Especificaciones.Show()
    End Sub

    Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Button20.Click
        ProgressBar1.Value = 0
        Timer1.Start()
        ProgressBar1.Visible = True

    End Sub

    Private Sub CheckBox11_CheckedChanged_1(sender As Object, e As EventArgs) Handles CheckBox11.CheckedChanged
        If CheckBox11.Checked = True Then
            TrackBar4.Visible = True
            TextBox5.Visible = True
        Else
            TrackBar4.Visible = False
            TextBox5.Visible = False
        End If
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        ProgressBar1.Value += 1
        If ProgressBar1.Value = 100 Then
            Timer1.Stop()
            ProgressBar1.Visible = False
            Dim str As String = "HARDWARE\DESCRIPTION\System\CentralProcessor"
            Dim cpuCount As Integer = My.Computer.Registry.LocalMachine.OpenSubKey(str, False).SubKeyCount
            CheckBox5.CheckState = CheckState.Checked
            TrackBar1.Value = (cpuCount.ToString)
            TextBox2.Text = (cpuCount.ToString)
            CheckBox7.CheckState = CheckState.Checked
            TextBox3.Text = (GetInfo(InfoTypes.VideocardMem))
            TrackBar3.Value = (GetInfo(InfoTypes.VideocardMem))
            CheckBox6.CheckState = CheckState.Checked
            CheckBox2.CheckState = CheckState.Checked
            CheckBox3.CheckState = CheckState.Checked
            CheckBox4.CheckState = CheckState.Checked
            CheckBox9.CheckState = CheckState.Checked
            CheckBox18.CheckState = CheckState.Checked
            Dim video As Integer
            video = (GetInfo(InfoTypes.VideocardMem))
            If video > "4100" Then
                video = "4100"
            End If
            TextBox3.Text = video
            TrackBar3.Value = video
            Dim ram As Integer
            ram = (GetInfo(InfoTypes.AmountOfMemory))
            If ram > "8000" Then
                ram = "8000"
            End If
            TextBox4.Text = ram
            TrackBar2.Value = ram
            If cpuCount >= "4" Then
                CheckBox11.CheckState = CheckState.Checked
                TrackBar4.Value = "7"
                TextBox5.Text = "7"
            Else
                If cpuCount = "2" Then
                    CheckBox11.CheckState = CheckState.Checked
                    TrackBar4.Value = "3"
                    TextBox5.Text = "3"
                Else
                    CheckBox11.CheckState = CheckState.Unchecked
                    TrackBar4.Value = ""
                    TextBox5.Text = ""
                End If
            End If
        End If
    End Sub

    Private Sub CheckBox12_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox12.CheckedChanged
        Dim steampath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Valve\Steam", "InstallPath", Nothing)
        Label2.Text = steampath & "\SteamApps\common\Arma 3\arma3.exe"
        Label10.Text = steampath & "\SteamApps\common\Arma 3"
        If CheckBox12.CheckState = CheckState.Checked Then
            Label2.Visible = False
            Label10.Visible = False
            TextBox8.Visible = True
            TextBox9.Visible = True
            Button21.Visible = True
            Button22.Visible = True
        Else
            Label2.Visible = True
            Label10.Visible = True
            TextBox8.Visible = False
            TextBox9.Visible = False
            Button21.Visible = False
            Button22.Visible = False
            TextBox8.Text = ""
            TextBox9.Text = ""
        End If
    End Sub

    Private Sub Button21_Click(sender As Object, e As EventArgs)

    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        Dim itemelegido As String
        itemelegido = ListBox1.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = itemelegido & extension
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = itemelegido & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)





        TextBox7.Text = ""
        If outpout = "Por Defecto.txt" Then
            MessageBox.Show("Este es el perfil por defecto no puede borrarlo.")
        Else
            Try
                My.Computer.FileSystem.DeleteFile(rutaguardado)
                My.Computer.FileSystem.DeleteFile(rutaguardadolista)

            Catch ex As Exception

            End Try
        End If

        ComboBox1.Items.Clear()
        ListBox1.Items.Clear()
        For Each myCoolFile As String In My.Computer.FileSystem.GetFiles _
        (programDataFilePath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
            ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))
            ListBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(myCoolFile))

        Next
        Dim itemlistbox As String
        ListBox1.SelectedItem = "Por Defecto"
        itemlistbox = ListBox1.SelectedItem
        ListBox1.Items.Remove(itemlistbox)
        ListBox1.Items.Insert(0, itemlistbox)
        ListBox1.SelectedIndex = 0
        Dim comboboxitem As String
        ComboBox1.SelectedItem = "Por Defecto"
        comboboxitem = ComboBox1.SelectedItem
        ComboBox1.Items.Remove(comboboxitem)
        ComboBox1.Items.Insert(0, comboboxitem)
        ComboBox1.SelectedIndex = 0
        ListBox1.SelectedItem = Nothing

    End Sub

    Private Sub CheckBox14_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox14.CheckedChanged

    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click

    End Sub

    Private Sub Button21_Click_1(sender As Object, e As EventArgs) Handles Button21.Click
        Dim ofd As New OpenFileDialog
        ofd.Title = "Elige la ruta de arma3.exe"
        ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

        Dim dr As DialogResult = ofd.ShowDialog

        If dr = Windows.Forms.DialogResult.OK Then
            TextBox8.Text = IO.Path.GetDirectoryName(ofd.FileName)
            TextBox8.Text = ofd.FileName
        End If

    End Sub

    Private Sub Button22_Click(sender As Object, e As EventArgs) Handles Button22.Click
        If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then
            TextBox9.Text = FolderBrowserDialog1.SelectedPath
        End If
    End Sub


    Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged

    End Sub

    Private Sub Button23_Click(sender As Object, e As EventArgs) Handles Button23.Click
        Contacto.Show()
    End Sub

    Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click

    End Sub

    Private Sub Button24_Click(sender As Object, e As EventArgs) Handles Button24.Click
        Label1.Visible = True

        Label1.Text = "¡Datos Guardados!"
        Label1.Refresh()
        System.Threading.Thread.Sleep(500)
        Label1.Visible = False
        My.Settings.saltarpantalla = CheckBox2.CheckState
        My.Settings.modoventana = CheckBox1.CheckState
        My.Settings.mundovacio = CheckBox3.CheckState
        My.Settings.ningunapausa = CheckBox4.CheckState
        My.Settings.mostrarerrores = CheckBox8.CheckState
        My.Settings.trackir = CheckBox13.CheckState
        My.Settings.freetrack = CheckBox15.CheckState
        My.Settings.nologs = CheckBox9.CheckState
        My.Settings.fraps = CheckBox14.CheckState
        My.Settings.memoriaram = CheckBox6.CheckState
        My.Settings.memoriavideo = CheckBox7.CheckState
        My.Settings.numerodecpu = CheckBox5.CheckState
        My.Settings.activarhyper = CheckBox10.CheckState
        My.Settings.logindesarrollo = Label9.Text
        My.Settings.extrahiloscheck = CheckBox11.CheckState
        My.Settings.rutacarpetaa3 = TextBox9.Text
        My.Settings.rutacambiada = TextBox8.Text
        My.Settings.rutaarmacheck = CheckBox12.CheckState
        My.Settings.despuesdelanzar = Me.ComboBox3.SelectedItem
        My.Settings.modoadministrador = CheckBox16.CheckState
        My.Settings.solopbo = CheckBox17.CheckState
        My.Settings.saltarintro = CheckBox18.CheckState
        My.Settings.dx9 = CheckBox19.CheckState
        My.Settings.Save()

        Dim sb As New System.Text.StringBuilder
        For Each itm As String In CheckedListBox2.CheckedItems
            sb.AppendLine(itm)
        Next
        If sb.ToString.Length >= 0 Then
            My.Computer.FileSystem.WriteAllText(perfilesuson, sb.ToString, False)
        End If

        Dim s As New IO.StreamWriter(perfilesusprioridadon)
        For i As Integer = 0 To ListBox3.Items.Count - 1
            s.Write(ListBox3.Items(i) & vbNewLine)
        Next
        s.Close()




    End Sub

    Private Sub CheckedListBox2_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles CheckedListBox2.SelectedIndexChanged
        ListBox3.Items.Clear()
        If CheckedListBox2.CheckedItems.Count > 0 Then
            For i As Integer = 0 To CheckedListBox2.CheckedItems.Count - 1
                ListBox3.Items.Add(CheckedListBox2.CheckedItems(i))
            Next
        End If
    End Sub

    Private Sub Button28_Click(sender As Object, e As EventArgs) Handles Button28.Click
        Dim checked As Boolean = False
        For i As Integer = 0 To CheckedListBox2.Items.Count - 1
            CheckedListBox2.SetItemChecked(i, checked)
        Next
        ListBox3.Items.Clear()
        For Each item In CheckedListBox2.CheckedItems
            ListBox3.Items.Add(item.ToString)
        Next
    End Sub

    Private Sub Button27_Click(sender As Object, e As EventArgs) Handles Button27.Click
        Dim checked As Boolean = True
        For i As Integer = 0 To CheckedListBox2.Items.Count - 1
            CheckedListBox2.SetItemChecked(i, checked)
        Next
        ListBox3.Items.Clear()
        For Each item In CheckedListBox2.CheckedItems
            ListBox3.Items.Add(item.ToString)
        Next
    End Sub

    Private Sub Button25_Click(sender As Object, e As EventArgs) Handles Button25.Click
        For i As Integer = 0 To CheckedListBox2.Items.Count - 1
            If CheckedListBox2.GetItemChecked(i) = True Then
                CheckedListBox2.SetItemChecked(i, False)
            ElseIf CheckedListBox2.GetItemChecked(i) = False Then
                CheckedListBox2.SetItemChecked(i, True)
            End If
        Next
    End Sub

    Private Sub Button26_Click(sender As Object, e As EventArgs) Handles Button26.Click
        CheckedListBox2.Items.Clear()
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@Blast*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@JSR*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@VTS_*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        If My.Computer.FileSystem.FileExists(perfilesuson) Then
            Try
                Using rdr As New System.IO.StreamReader(perfilesuson)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox2.Items.Count - 1
                                If CheckedListBox2.Items(i).ToString = itm Then
                                    CheckedListBox2.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If

        If IO.File.Exists(perfilesusprioridadon) Then
            Try
                Dim r As New IO.StreamReader(perfilesusprioridadon)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox3.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox3.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try
        End If
    End Sub

    Private Sub Button30_Click(sender As Object, e As EventArgs) Handles Button30.Click
        Dim item As String
        item = ListBox3.SelectedItem
        ListBox3.Items.Remove(item)
        ListBox3.Items.Insert(0, item)
        ListBox3.SelectedIndex = 0
    End Sub

    Private Sub Button32_Click(sender As Object, e As EventArgs) Handles Button32.Click
        If ListBox3.SelectedIndex > 0 Then
            Dim I = ListBox3.SelectedIndex - 1
            ListBox3.Items.Insert(I, ListBox3.SelectedItem)
            ListBox3.Items.RemoveAt(ListBox3.SelectedIndex)
            ListBox3.SelectedIndex = I
        End If
    End Sub

    Private Sub Button31_Click(sender As Object, e As EventArgs) Handles Button31.Click
        If ListBox3.SelectedIndex < ListBox3.Items.Count - 1 Then
            Dim I = ListBox3.SelectedIndex + 2
            ListBox3.Items.Insert(I, ListBox3.SelectedItem)
            ListBox3.Items.RemoveAt(ListBox3.SelectedIndex)
            ListBox3.SelectedIndex = I - 1
        End If
    End Sub

    Private Sub Button29_Click(sender As Object, e As EventArgs) Handles Button29.Click
        Dim limite As Integer = (ListBox3.Items.Count - 1)
        Dim item As String
        item = ListBox3.SelectedItem
        ListBox3.Items.Remove(item)
        ListBox3.Items.Insert(limite, item)
        ListBox3.SelectedIndex = limite
    End Sub

    Private Sub CheckBox17_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox17.CheckedChanged
        If CheckBox17.CheckState = CheckState.Checked Then
            solopbo = "-noFilePatching"
        Else
            solopbo = Nothing
        End If
    End Sub

    Private Sub CheckBox18_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox18.CheckedChanged
        If CheckBox18.CheckState = CheckState.Checked Then
            saltarintro = "-skipIntro"
        Else
            saltarintro = Nothing
        End If
    End Sub

    Private Sub CheckBox19_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox19.CheckedChanged
        If CheckBox19.CheckState = CheckState.Checked Then
            dx9 = "-winxp"
        Else
            dx9 = Nothing
        End If
    End Sub

    
    Private Sub ProgressBar1_Click(sender As Object, e As EventArgs) Handles ProgressBar1.Click

    End Sub

    Private Sub Button33_Click(sender As Object, e As EventArgs) Handles Button33.Click
        CheckedListBox1.Visible = True
        CheckedListBox2.Visible = False
        CheckedListBox3.Visible = False
        TabPage3.Enabled = True
        ListBox3.Visible = False
        ListBox4.Visible = False


        Button1.Visible = True
        Button2.Visible = False
        CheckedListBox1.Enabled = True
        ListBox5.Visible = False
        CheckedListBox1.Visible = True
        CheckedListBox2.Visible = False
        ComboBox2.Visible = False
        ComboBox1.Visible = True
        Button24.Visible = False
        Button3.Visible = True
        CheckedListBox1.Items.Clear()
        ListBox2.Visible = True
        ListBox3.Visible = False
        Button9.Visible = True
        Button10.Visible = True
        Button11.Visible = True
        Button12.Visible = True
        Button29.Visible = False
        Button30.Visible = False
        Button31.Visible = False
        Button32.Visible = False
        Button4.Visible = True
        Button7.Visible = True
        Button17.Visible = True
        Button13.Visible = True
        Label12.Visible = False
        Button25.Visible = False
        Button26.Visible = False
        Button27.Visible = False
        Button28.Visible = False

        CheckedListBox1.Refresh()

        Try
            For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@*")
                CheckedListBox1.Items.Add(Path.GetFileName(folder))
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        Dim seleccion As String = ComboBox1.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Using rdr As New System.IO.StreamReader(rutaguardado)
                Do While rdr.Peek() >= 0
                    Dim itm As String = rdr.ReadLine
                    itm = itm.Trim

                    If itm <> "" Then
                        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                            If CheckedListBox1.Items(i).ToString = itm Then
                                CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
                                Exit For
                            End If
                        Next
                    End If
                Loop
            End Using
        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Dim r As New IO.StreamReader(rutaguardadolista)
            Dim txt As New TextBox
            txt.Text = r.ReadToEnd
            ListBox2.Items.Clear()
            For i As Integer = 0 To txt.Lines.Count - 2
                ListBox2.Items.Add(txt.Lines(i))
            Next
            r.Close()
        End If
    End Sub

    Private Sub Button35_Click(sender As Object, e As EventArgs) Handles Button35.Click
        CheckedListBox2.Visible = True
        CheckedListBox1.Visible = False
        CheckedListBox3.Visible = False
        ListBox3.Visible = True
        ListBox4.Visible = False
        TabPage3.Enabled = False
        Button2.Visible = True
        ListBox5.Visible = False
        Button1.Visible = False
        CheckedListBox1.Enabled = False
        CheckedListBox1.Items.Clear()
        CheckedListBox2.Items.Clear()
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@Blast*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@JSR*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@VTS_*")
            CheckedListBox2.Items.Add(Path.GetFileName(folder))
        Next
        TextBox6.Text = ""
        ComboBox2.Visible = True
        Button24.Visible = True
        Button3.Visible = False
        ComboBox1.Visible = False
        ListBox2.Items.Clear()
        ListBox2.Visible = False
        Button9.Visible = False
        Button10.Visible = False
        Button11.Visible = False
        Button12.Visible = False
        Button29.Visible = True
        Button30.Visible = True
        Label12.Visible = True
        Button31.Visible = True
        Button32.Visible = True
        Button4.Visible = False
        Button7.Visible = False
        Button17.Visible = False
        Button13.Visible = False

        Button25.Visible = True
        Button26.Visible = True
        Button27.Visible = True
        Button28.Visible = True
        Dim clientsidearchivo As String = "clientside.txt"

        Dim clientside As String = Combine(carpetaa3, clientsidearchivo)
        If My.Computer.FileSystem.FileExists(perfilesuson) Then
            Try
                Using rdr As New System.IO.StreamReader(perfilesuson)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox2.Items.Count - 1
                                If CheckedListBox2.Items(i).ToString = itm Then
                                    CheckedListBox2.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If

        If My.Computer.FileSystem.FileExists(clientside) Then
            Try
                Using rdr As New System.IO.StreamReader(clientside)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox2.Items.Count - 1
                                If CheckedListBox2.Items(i).ToString = itm Then
                                Else
                                    CheckedListBox2.Items.Add(itm)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If


        If IO.File.Exists(perfilesusprioridadon) Then
            Try
                Dim r As New IO.StreamReader(perfilesusprioridadon)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox3.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox3.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try
        End If


    End Sub

  

    Private Sub Button34_Click(sender As Object, e As EventArgs) Handles Button34.Click
        Button29.Visible = False
        Button30.Visible = False
        TextBox7.Visible = True
        TabPage3.Enabled = False
        Button31.Visible = False
        Button32.Visible = False
        Button9.Visible = False
        Button10.Visible = False
        Button11.Visible = False
        Button24.Visible = False
        Button3.Visible = False
        Button12.Visible = False
        Button25.Visible = False
        Button26.Visible = False
        Button27.Visible = False
        Button28.Visible = False
        Button4.Visible = False
        Button7.Visible = False
        Button13.Visible = False
        Button17.Visible = False
        Button1.Visible = True
        ListBox5.Visible = True
        Button2.Visible = False
        CheckedListBox1.Visible = False
        CheckedListBox2.Visible = False
        CheckedListBox3.Visible = True
        ListBox2.Visible = False
        ListBox3.Visible = False
        ListBox4.Visible = True
        ComboBox1.Visible = False
        ComboBox2.Visible = False
        CheckedListBox1.Items.Clear()
        Label12.Visible = False
      
        CheckedListBox3.Refresh()

        Try
            For Each folder In System.IO.Directory.GetDirectories(carpetaa3, "@*")
                CheckedListBox3.Items.Add(Path.GetFileName(folder))
            Next
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
        Try
            Dim seleccion As String = ListBox5.SelectedItem.ToString
        Catch ex As Exception

        End Try
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox3.Items.Count - 1
            CheckedListBox3.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Using rdr As New System.IO.StreamReader(rutaguardado)
                Do While rdr.Peek() >= 0
                    Dim itm As String = rdr.ReadLine
                    itm = itm.Trim

                    If itm <> "" Then
                        For i As Integer = 0 To CheckedListBox3.Items.Count - 1
                            If CheckedListBox3.Items(i).ToString = itm Then
                                CheckedListBox3.SetItemCheckState(i, CheckState.Checked)
                                Exit For
                            End If
                        Next
                    End If
                Loop
            End Using
        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Dim r As New IO.StreamReader(rutaguardadolista)
            Dim txt As New TextBox
            txt.Text = r.ReadToEnd
            ListBox4.Items.Clear()
            For i As Integer = 0 To txt.Lines.Count - 2
                ListBox4.Items.Add(txt.Lines(i))
            Next
            r.Close()
        End If
    End Sub

    Private Sub ListBox5_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox5.SelectedIndexChanged
        Dim seleccion As String = ListBox5.SelectedItem.ToString
        Dim extension As String = ".txt"
        Dim outpout As String
        outpout = seleccion & extension
        For i As Integer = 0 To CheckedListBox1.Items.Count - 1
            CheckedListBox1.SetItemCheckState(i, CheckState.Unchecked)
        Next
        Dim rutaguardado As String
        rutaguardado = Combine(programDataFilePath, outpout)
        If My.Computer.FileSystem.FileExists(rutaguardado) Then
            Try
                Using rdr As New System.IO.StreamReader(rutaguardado)
                    Do While rdr.Peek() >= 0
                        Dim itm As String = rdr.ReadLine
                        itm = itm.Trim

                        If itm <> "" Then
                            For i As Integer = 0 To CheckedListBox1.Items.Count - 1
                                If CheckedListBox1.Items(i).ToString = itm Then
                                    CheckedListBox1.SetItemCheckState(i, CheckState.Checked)
                                    Exit For
                                End If
                            Next
                        End If
                    Loop
                End Using
            Catch ex As Exception

            End Try

        End If


        Dim extensionlista As String = ".prioridad.dat"
        Dim outpoutlista As String = seleccion & extensionlista
        Dim rutaguardadolista As String
        rutaguardadolista = Combine(programDataFilePath, outpoutlista)
        If IO.File.Exists(rutaguardadolista) Then
            Try
                Dim r As New IO.StreamReader(rutaguardadolista)
                Dim txt As New TextBox
                txt.Text = r.ReadToEnd
                ListBox2.Items.Clear()
                For i As Integer = 0 To txt.Lines.Count - 2
                    ListBox2.Items.Add(txt.Lines(i))
                Next
                r.Close()
            Catch ex As Exception

            End Try
        End If
    End Sub

    Private Sub CheckedListBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CheckedListBox3.SelectedIndexChanged
        ListBox4.Items.Clear()
        If CheckedListBox3.CheckedItems.Count > 0 Then
            For i As Integer = 0 To CheckedListBox3.CheckedItems.Count - 1
                ListBox4.Items.Add(CheckedListBox3.CheckedItems(i))
            Next
        End If
    End Sub

    Private Sub Button36_Click(sender As Object, e As EventArgs) Handles Button36.Click
        Me.Close()
    End Sub

    Private Sub Button37_Click(sender As Object, e As EventArgs) Handles Button37.Click
        Me.WindowState = System.Windows.Forms.FormWindowState.Minimized
    End Sub

End Class
